Micron Document
🎖️GitЯра🎖️

Node / meshtastic / Meshtastic-Android / files / core / testing / src / commonMain / kotlin / org / meshtastic / core / testing / FakeDatabaseProvider.kt

Displaying Raw • Download

core/testing/src/commonMain/kotlin/org/meshtastic/core/testing/FakeDatabaseProvider.kt 41414f832f938b655c97bc07509bc140ea16e2a3 (41414f83) Text, 2.50 KB

T8b949e/*
* Copyright (c) 2026 Meshtastic LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
Tff7b72package T7ee787org.meshtastic.core.testing

Tff7b72import T7ee787kotlinx.coroutines.ExperimentalCoroutinesApi
Tff7b72import T7ee787kotlinx.coroutines.flow.Flow
Tff7b72import T7ee787kotlinx.coroutines.flow.MutableStateFlow
Tff7b72import T7ee787kotlinx.coroutines.flow.StateFlow
Tff7b72import T7ee787kotlinx.coroutines.flow.flatMapLatest
Tff7b72import T7ee787org.meshtastic.core.database.DatabaseProvider
Tff7b72import T7ee787org.meshtastic.core.database.MeshtasticDatabase
Tff7b72import T7ee787org.meshtastic.core.database.getInMemoryDatabaseBuilder
Tff7b72import T7ee787kotlin.concurrent.Volatile

T8b949e/** A real [DatabaseProvider] that uses an in-memory database for testing. */
Tf0883e@OptInTb4b4b4(Te6edf3ExperimentalCoroutinesApiTff7b72::Te6edf3classTb4b4b4)
Tff7b72class T56d364FakeDatabaseProvider Tb4b4b4: Te6edf3DatabaseProvider Tb4b4b4{
Tf0883e@Volatile Tff7b72private Tff7b72var Te6edf3dbTb4b4b4: Te6edf3MeshtasticDatabase Tff7b72= Te6edf3getInMemoryDatabaseBuilderTb4b4b4(Tb4b4b4)Tb4b4b4.Te6edf3buildTb4b4b4(Tb4b4b4)
Tff7b72private Tff7b72val Te6edf3_currentDb Tff7b72= Te6edf3MutableStateFlowTb4b4b4(Te6edf3dbTb4b4b4)
Tff7b72override Tff7b72val Te6edf3currentDbTb4b4b4: Te6edf3StateFlowTff7b72<Te6edf3MeshtasticDatabaseTff7b72> Tff7b72= Te6edf3_currentDb

T8b949e/** Optional barrier/fault hook used to prove overlapping repository writes before they enter Room. */
Tff7b72var Te6edf3beforeWithDbTb4b4b4: Te6edf3suspend Tb4b4b4(Tb4b4b4) Tff7b72-Tff7b72> Tffa657Unit Tff7b72= Tb4b4b4{Tb4b4b4}

Tff7b72override Tff7b72fun Tff7b72<Te6edf3TTff7b72> Td2a8ffobserveCurrentDbTb4b4b4(Te6edf3queryTb4b4b4: Tb4b4b4(Te6edf3MeshtasticDatabaseTb4b4b4) Tff7b72-Tff7b72> Te6edf3FlowTff7b72<Te6edf3TTff7b72>Tb4b4b4)Tb4b4b4: Te6edf3FlowTff7b72<Te6edf3TTff7b72> Tff7b72= Te6edf3currentDbTb4b4b4.Te6edf3flatMapLatestTb4b4b4(Te6edf3queryTb4b4b4)

Tff7b72override Tff7b72suspend Tff7b72fun Tff7b72<Te6edf3TTff7b72> Td2a8ffwithReadDbTb4b4b4(Te6edf3blockTb4b4b4: Te6edf3suspend Tb4b4b4(Te6edf3MeshtasticDatabaseTb4b4b4) Tff7b72-Tff7b72> Te6edf3TTb4b4b4)Tb4b4b4: Te6edf3T Tff7b72= Te6edf3blockTb4b4b4(Te6edf3dbTb4b4b4)

Tff7b72override Tff7b72suspend Tff7b72fun Tff7b72<Te6edf3TTff7b72> Td2a8ffwithDbTb4b4b4(Te6edf3blockTb4b4b4: Te6edf3suspend Tb4b4b4(Te6edf3MeshtasticDatabaseTb4b4b4) Tff7b72-Tff7b72> Te6edf3TTb4b4b4)Tb4b4b4: Te6edf3T? Tb4b4b4{
Te6edf3beforeWithDbTb4b4b4(Tb4b4b4)
Tff7b72return Te6edf3blockTb4b4b4(Te6edf3dbTb4b4b4)
Tb4b4b4}

T8b949e/**
* Simulates the active-DB switch that happens when the app selects a different device — the new DB has no rows, so
* any cache that lived only in the previous DB is gone. Closes the prior DB to free its resources.
*/
Tff7b72fun Td2a8ffswitchToNewDatabaseTb4b4b4(Tb4b4b4) Tb4b4b4{
Tff7b72val Te6edf3previous Tff7b72= Te6edf3db
Te6edf3db Tff7b72= Te6edf3getInMemoryDatabaseBuilderTb4b4b4(Tb4b4b4)Tb4b4b4.Te6edf3buildTb4b4b4(Tb4b4b4)
Te6edf3_currentDbTb4b4b4.Te6edf3value Tff7b72= Te6edf3db
Te6edf3previousTb4b4b4.Te6edf3closeTb4b4b4(Tb4b4b4)
Tb4b4b4}

Tff7b72fun Td2a8ffcloseTb4b4b4(Tb4b4b4) Tb4b4b4{
Te6edf3dbTb4b4b4.Te6edf3closeTb4b4b4(Tb4b4b4)
Tb4b4b4}
Tb4b4b4}

Served by rngit 1.5.0 - Generated in 0.04s